import React, {useEffect} from "react";
import {Button, Col, DatePicker, Form, Input, Modal, Row, Select} from "antd";
import {JobDescription} from "@/types/resp/jobDescription";

interface JobDescriptionViewProps {
  visible: boolean;
  viewRow: object;
  onCloseJobDescriptionView: () => void;
}

const JobDescriptionView: React.FC<JobDescriptionViewProps> = ({visible, viewRow, onCloseJobDescriptionView}) => {

  const [form] = Form.useForm<JobDescription>();

  const onBack = () => {
    onCloseJobDescriptionView()
  };

  useEffect(() => {
    if (!visible) {
      return
    }
    if (viewRow) {
      form.setFieldsValue(viewRow);
    }
  }, [viewRow]);

  const addFooter = (
    <div className='custom-footer'>
      <Button type="primary" onClick={onBack}>关闭</Button>
    </div>
  );

  return (
    <Modal title={"招聘岗位详情"} open={visible} onCancel={onCloseJobDescriptionView}
        width={'var(--modal-width)'} footer={addFooter} style={{marginTop: 'var(--modal-margin-top)'}}>
      <Form form={form} labelCol={{span: 6}} disabled={true}>
        <Row gutter={10}>
          <Col span={11}>
            <Form.Item name="enterpriseName" label="企业名称">
              <Input/>
            </Form.Item>
          </Col>
          <Col span={11}>
            <Form.Item name="jobTitle" label="岗位名称">
              <Input/>
            </Form.Item>
          </Col>
        </Row>
        <Row gutter={10}>
          <Col span={11}>
            <Form.Item name="departmentName" label="部门名称">
              <Input/>
            </Form.Item>
          </Col>
          <Col span={11}>
            <Form.Item name="workLocation" label="工作地点">
              <Input/>
            </Form.Item>
          </Col>
        </Row>
        <Row gutter={10}>
          <Col span={11}>
            <Form.Item name="jobType" label="岗位类型">
              <Select placeholder="请选择岗位类型" options={[
                { value: 10, label: <span>全职</span> },
                { value: 20, label: <span>兼职</span> },
                { value: 30, label: <span>实习</span> }
              ]} />
            </Form.Item>
          </Col>
          <Col span={11}>
            <Form.Item name="salaryRange" label="薪资范围">
              <Select placeholder="请选择薪资范围" options={[
                { value: 1, label: <span>3000~5000</span> },
                { value: 2, label: <span>5001~10000</span> },
                { value: 3, label: <span>10001~20000</span> },
                { value: 4, label: <span>20001~30000</span> },
                { value: 5, label: <span>30000以上</span> }
              ]} />
            </Form.Item>
          </Col>
        </Row>
        <Row gutter={10}>
          <Col span={11}>
            <Form.Item name="postingDate" label="发布日期">
              <DatePicker/>
            </Form.Item>
          </Col>
          <Col span={11}>
            <Form.Item name="closingDate" label="截止日期">
              <DatePicker/>
            </Form.Item>
          </Col>
        </Row>
        <Row gutter={10}>
          <Col span={11}>
            <Form.Item name="headCount" label="招聘人数">
              <Input/>
            </Form.Item>
          </Col>
          <Col span={11}>
            <Form.Item name="status" label="状态">
              <Select placeholder="请选择状态" options={[
                { value: 10, label: <span>开放</span> },
                { value: 20, label: <span>关闭</span> }
              ]} />
            </Form.Item>
          </Col>
        </Row>
        <Row gutter={10}>
          <Col span={22}>
            <Form.Item name="responsibilities" label="岗位职责" labelCol={{span: 3}}>
              <Input.TextArea autoSize={{ minRows: 3, maxRows: 3 }}/>
            </Form.Item>
          </Col>
        </Row>
        <Row gutter={10}>
          <Col span={22}>
            <Form.Item name="requirement" label="岗位要求" labelCol={{span: 3}}>
              <Input.TextArea autoSize={{ minRows: 3, maxRows: 3 }}/>
            </Form.Item>
          </Col>
        </Row>
        <Row gutter={10}>
          <Col span={11}>
            <Form.Item name="createTime" label="创建时间">
              <Input/>
            </Form.Item>
          </Col>
          <Col span={11}>
            <Form.Item name="modifyTime" label="最后修改时间">
              <Input/>
            </Form.Item>
          </Col>
        </Row>
      </Form>
    </Modal>
  )
}

export default JobDescriptionView;
